<template>
  <div>
    <cityHeader></cityHeader>
    <citySearch :cities='cities'></citySearch>
    <cityList :cities='cities' :hotCities='hotCities' :letter="letter"></cityList>
    <cityAlphabet :cities='cities' @change="handerLetterChange"></cityAlphabet>
  </div>
</template>

<script>
import cityHeader from "./components/Header.vue";
import citySearch from "./components/Search.vue";
import cityList from "./components/List.vue";
import cityAlphabet from "./components/Alphabet.vue";
import axios from "axios";

export default {
  name: "city",
  components: {
    cityHeader,
    citySearch,
    cityList,
    cityAlphabet,
  },
  data() {
    return {
      cities: {},
      hotCities: [],
      letter:""
    };
  },
  methods: {
    getCityInfo() {
      axios.get("/api/city.json").then(this.handleGetCityInfoSucc);
    },
    handleGetCityInfoSucc(res) {
      // console.log(res);
      // 此时传入的res是一个promise对象，它内部的data属性才是我们要请求的数据，所以
      res = res.data;
      if (res.ret && res.data) {
        this.cities = res.data.cities;
        this.hotCities = res.data.hotCities;
      }
    },
    handerLetterChange (letter){
      this.letter = letter
    } 
  },
  mounted() {
    this.getCityInfo();
  },

};
</script>

<style lang='stylus' scoped></style>